<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
include("kn.php");
include("check_userlogin.php");
$Malaptop = $_GET["Malaptop"];
$kt = 0;
for($i = 1; $i <= $_SESSION["tongsp"];$i++)
{
	if($_GET["Malaptop"]==$_SESSION["Malaptop".$i])
	{
	$kt = 1;
	$_SESSION["Soluong".$i]++;
	break;
	}
}
	if($kt==0)
	{
	$lenh = "select * from laptop where Malaptop='$Malaptop'";
	$kq = mysql_query($lenh);
	$n = mysql_num_rows($kq);
	if($n >0)
	{
	$_SESSION["tongsp"]++;
	$row = mysql_fetch_assoc($kq);
	$j = $_SESSION["tongsp"];
	session_register("Malaptop".$j);
	$_SESSION["Malaptop".$j]=$row["Malaptop"];
	session_register("Tenlaptop".$j);
	$_SESSION["Tenlaptop".$j]=$row["Tenlaptop"];
	session_register("Dongia".$j);
	$_SESSION["Dongia".$j]=$row["Dongia"];
	session_register("Soluong".$j);
	$_SESSION["Soluong".$j]=1;
	}
	}
?>

<form id="form1" name="form1" method="post" action="capnhatgiohang.php">
  <table width="550" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFCCCC" bordercolor="#FFCC66" style="border-collapse:collapse">
    <tr>
      <td height="35" colspan="6" align="center"><p><strong>DANH SÁCH ĐẶT HÀNG</strong></p>
      <p>
        <input type="button" name="tieptuc" id="tieptuc" value="Tiếp tục mua hàng" onclick="javascript:history.go(-1)" />
    </p></td>
    </tr>
    <tr>
      <td align="center">STT</td>
      <td align="center">Tên laptop</td>
      <td align="center">Đơn giá</td>
      <td align="center">Số lượng</td>
      <td align="center">Thành tiền</td>
      <td align="center">Xóa</td>
    </tr>
    <?php
    for($i = 1; $i <= $_SESSION["tongsp"]; $i++)
	{
	?>
    <tr>
      <td align="center"><?php  echo $i;  ?></td>
      <td align="center"><?php echo $_SESSION["Tenlaptop".$i];   ?></td>
      <td align="center"><?php echo $_SESSION["Dongia".$i];   ?></td>
      <td align="center"><label for="soluong"></label>
      <input name="C<?php echo $i  ?>" type="text" id="soluong" size="10" value="<?php echo $_SESSION["Soluong".$i];    ?>" /></td>
      <td align="center"><?php echo $_SESSION["Soluong".$i]*$_SESSION["Dongia".$i];    ?></td>
      <td align="center"><input type="checkbox" name="X<?php echo $i;   ?>" id="xoa" />
      <label for="xoa"></label></td>
    </tr>
    <?php
    }
	?>
  </table>
  <p align="center">Tổng tiền: <font color="#00FF00"><b><?php echo tongtien();   ?> </b></font>VNĐ</p>
  <p align="center">
    <input type="submit" name="capnhat" id="capnhat" value="Cập nhật" />
    <input type="button" name="dathang" id="dathang" value="Đặt hàng" onclick="location.href='dathang.php'" />
    <input type="submit" name="xoa" id="xoa" value="Xóa" />
  </p>
      <?php
	function tongtien()
	{
	$s= 0;
	for($i = 1; $i <= $_SESSION["tongsp"];$i++)
	{
	$s = $s + $_SESSION["Soluong".$i]*$_SESSION["Dongia".$i];
	
	}
	return $s;
	}
	
	?>

</form>
</body>
</html>